Ti.include('animation.js');

var tmpWin = function(pTitle, pData){
	var tmp = Titanium.UI.createWindow({
		top: 0,
		width: 320,
		height: 410,
		backgroundImage: "media/images/bglist.png",
	})
	
	var barTop = Titanium.UI.createView({
		top: 0,
		width: 320,
		height: 44,
		backgroundImage: "media/images/bar-top.png",
	});
	var title = Ti.UI.createImageView({
		image: 'media/home/images/' + pTitle + ".png",
		left: 0,
		top: 0,
		width: 320,
		height: 44,
		zIndex: 99
	})
	barTop.add(title);
	tmp.add(barTop);
	
	var cover = Ti.UI.createImageView({
		image: 'media/images/cover.png',
		left: 0,
		top: 44,
		width: 320,
		height: 33,
		zIndex: 9999
	})
	tmp.add(cover);
	
	
	var btnBack = Ti.UI.createButton({
		image: "media/nav/btn_back.png",
		top: 10,
		left: 15,
		width: 54,
		height: 25
	})			
	btnBack.addEventListener('click', function(e){
		animateIt(tmp, 'LOut');
	})
	tmp.add(btnBack);
	//animateIt(tmp, 'LIn');
	
	dView.data = homeData(dView, pData);
	tmp.add(dView);
	
	return tmp;
}

var dView = Titanium.UI.createTableView({
	width: 320,
	left: 0,
	top: 50,
	zIndex: 999,
	backgroundColor: "transparent",
	separatorStyle: Ti.UI.iPhone.TableViewSeparatorStyle.NONE,
	id: 'dView'
	
});


var homeData = function(pRoot, jsonData){
	
	var dTable = [];
	for(var k in jsonData){
		var rowData = Titanium.UI.createTableViewRow({
			height: 60,
			backgroundImage: "media/images/line.png",
		});
		
		var mNews = Ti.UI.createImageView({
			image: getCorrectFile(jsonData[k].img + "1.png"),
			left: 0,
			top: 0,
			width: 320,
			height: 59
		});
		
		rowData.add(mNews);
		dTable.push(rowData);
	}
	pRoot.addEventListener('click', function(e){
		Ti.include('detail.js');
		var wDe = new wDetail();
		wDe.dNews('magic', jsonData[e.index]);
	})
	return dTable;
}
